import {
  yiShuQianMing
} from '../../../../utils/http'

Page({
  fsize: 100, // 字体大小
  mirror: 'no', // 字体倒影（镜像）
  alpha: 'no', // 字体渐变
  shadow: 'no', // 字体投影
  data: {
    font: [{
      name: "叶根友疾风草",
      value: "jfcs.ttf"
    }, {
      name: "叶根友圆趣",
      value: "yqk.ttf"
    }, {
      name: "商务签名",
      value: "zql.ttf"
    }, {
      name: "合文签名",
      value: "haku.ttf"
    }, {
      name: "草体签名",
      value: "lfc.ttf"
    }, {
      name: "潇洒签名",
      value: "bzcs.ttf"
    }, {
      name: "叶根友签名",
      value: "qmt.ttf"
    }],
    fontIndex: 0, // 字体下标
    color: "#000000", // 字体上色
    vcolor: "#000000", // 字体下色
    bgcolor: "#ffffff", // 背景色
  },
  // 输入文字
  textInput(e) {
    this.text = e.detail.value
  },
  // 选择字体
  changeFont(e) {
    this.setData({
      fontIndex: e.detail.value
    })
  },
  // 弹出取色器
  colorPicker(e) {
    this.colorType = e.currentTarget.dataset.type
    this.setData({
      showColorPicker: true
    })
  },
  // 选择字体颜色
  changeColor(e) {
    this.colorType === 'color' ?
      this.setData({
        color: e.detail.color
      }) :
      this.colorType === 'vcolor' ?
      this.setData({
        vcolor: e.detail.color
      }) :
      this.setData({
        bgcolor: e.detail.color
      })

  },
  // 字体大小
  fsizeEvent(e) {
    this.fsize = e.detail.value
  },
  // 字体倒影
  mirrorEvent(e) {
    console.log(e.detail.value)
    this.mirror = e.detail.value ? 'yes' : 'no'
  },
  // 字体渐变
  alphaEvent(e) {
    console.log(e.detail.value)
    this.alpha = e.detail.value ? 'yes' : 'no'
  },
  // 字体投影
  shadowEvent(e) {
    console.log(e.detail.value)
    this.shadow = e.detail.value ? 'yes' : 'no'
  },
  createYiShuQianMing() {
    if (!this.text)
      return wx.showToast({
        title: '请输入签名文字',
        icon: 'error'
      })
    this.setData({
      src: `https://www.yishuzi.cn/qianming/image.png?fsize=${this.fsize}&font=${this.data.font[this.data.fontIndex].value}&text=${this.text}&mirror=${this.mirror}&color=${this.data.color.replace(/#/g,'')}&vcolor=${this.data.vcolor.replace(/#/g,'')}&bgcolor=${this.data.bgcolor.replace(/#/g,'')}&alpha=${this.alpha}&output=png&spacing=4&shadow=${this.shadow}&transparent=no&icon=no&iconic=&top_spacing=5&left_spacing=6&icon_size=48`
    })
  },
  onShareAppMessage() {
    return {
      title: "来领取你的专属艺术签名",
      path: "/pages/dailyTools/pages/artisticSignature/index",
      imageUrl: '/images/function_icon/artisticSignature.png',
    }
  },
  onShareTimeline() {
    return {
      title: '来领取你的专属艺术签名',
      imageUrl: '/images/function_icon/artisticSignature.png',
    }
  },
})